import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/workloads',
    component: Layout,
    redirect: '/workloads/deployments',
    name: '工作负载',
    meta: { title: '工作负载', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'deployments',
        name: 'Deployments',
        component: () => import('@/views/workloads/deplist'),
        meta: { title: 'Deployments列表', icon: 'table' }
      },
      {
        path: 'createdeploy',
        name: 'Createdeploy',
        component: () => import('@/views/deployments/deploy-create'),
        meta: { title: '创建/编辑Deployment', icon: 'table' }
      },

      {
        path: 'deploydetail',
        name: 'Deploydetail',
        component: () => import('@/views/deployments/deploy-detail'),
        meta: { title: 'Deployment详细', icon: 'table' },
        hidden: true
      },
      {
        path: 'pods',
        name: 'Pods',
        component: () => import('@/views/workloads/podslist'),
        meta: { title: 'Pods列表', icon: 'tree' }
      },
      {
        path: 'podlogs',
        name: 'Podlogs',
        component: () => import('@/views/workloads/podlogs')
        // meta: { title: '查看logs', icon: 'tree' }
      },
      {
        path: 'podshell',
        name: 'Podshell',
        component: () => import('@/views/workloads/podshell')
        // meta: { title: 'podshell', icon: 'tree' }
      },
      {
        path: 'serivces',
        name: 'Serivces',
        component: () => import('@/views/workloads/svclist'),
        meta: { title: 'Service列表', icon: 'tree' }
      }
    ]
  },

  {
    path: '/nodes',
    component: Layout,
    redirect: '/nodes/nodeshell',
    name: 'nodes',
    meta: { title: '节点管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'nodeshell',
        name: 'Nodeshell',
        component: () => import('@/views/nodes/nodeshell'),
        meta: { title: 'nodeshell', icon: 'table' }
      },
      {
        path: 'nodelist',
        name: 'Nodelist',
        component: () => import('@/views/nodes/nodelist'),
        meta: { title: '节点列表', icon: 'tree' }
      },
      {
        path: 'nodedetail',
        name: 'Nodedetail',
        component: () => import('@/views/nodes/nodedetail'),
        meta: { title: '节点编辑', icon: 'tree' },
        hidden: true
      }

    ]
  },

  {
    path: '/ingress',
    component: Layout,
    redirect: '/ingress/ingress-list',
    name: 'ingress',
    meta: { title: 'Ingress管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'ingress-list',
        name: 'Ingress-list',
        component: () => import('@/views/ingress/ingress-list'),
        meta: { title: 'Ingress列表', icon: 'table' }
      },
      {
        path: 'createingress',
        name: 'Createingress',
        component: () => import('@/views/ingress/ingress-create'),
        meta: { title: '创建ingress', icon: 'tree' }
      }

    ]
  },

  {
    path: '/resources',
    component: Layout,
    redirect: '/resources/secrets',
    name: 'resources',
    meta: { title: '资源管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'secrets',
        name: 'Secrets',
        component: () => import('@/views/resources/secretlist'),
        meta: { title: '密文列表', icon: 'table' }
      },
      {
        path: 'createsecret',
        name: 'createsecret',
        component: () => import('@/views/resources/secret-create'),
        meta: { title: '创建密文', icon: 'tree' }
      },
      {
        path: 'secretsget',
        name: 'Secretsget',
        component: () => import('@/views/resources/secret-get'),
        meta: { title: '查看密文', icon: 'table' },
        hidden: true
      },
      {
        path: 'configmaps',
        name: 'Configmaps',
        component: () => import('@/views/resources/configmaplist'),
        meta: { title: '配置列表', icon: 'tree' }
      },
      {
        path: 'createconfigmaps',
        name: 'CreateConfigmaps',
        component: () => import('@/views/resources/configmap-create'),
        meta: { title: '创建配置', icon: 'tree' }
      }

    ]
  },
  {
    path: '/rbac',
    component: Layout,
    redirect: '/rbac/rolelist',
    name: 'rbac',
    meta: { title: 'RBAC可视化管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'rolelist',
        name: 'Rolelist',
        component: () => import('@/views/rbac/rolelist'),
        meta: { title: '角色列表', icon: 'table' }
      },
      {
        path: 'rolebindinglist',
        name: 'Rolebindinglist',
        component: () => import('@/views/rbac/rolebindinglist'),
        meta: { title: '角色绑定', icon: 'tree' }
      },

      {
        path: 'createrolebinding',
        name: 'Createrolebinding',
        component: () => import('@/views/rbac/create-rolebinding'),
        meta: { title: '创建角色绑定', icon: 'tree' },
        hidden: true
      },
      {
        path: 'createclusterrolebinding',
        name: 'Createclusterrolebinding',
        component: () => import('@/views/rbac/create-clusterrolebinding'),
        meta: { title: '创建集群角色绑定', icon: 'tree' },
        hidden: true
      },
      {
        path: 'clusterrolelist',
        name: 'Clusterrolelist',
        component: () => import('@/views/rbac/clusterrolelist'),
        meta: { title: '集群角色列表', icon: 'tree' }
      },
      {
        path: 'clusterrolebindinglist',
        name: 'Clusterrolebindinglist',
        component: () => import('@/views/rbac/clusterrolebindinglist'),
        meta: { title: '集群角色绑定', icon: 'tree' }
      },
      {
        path: 'createrole',
        name: 'Createrole',
        component: () => import('@/views/rbac/create-role'),
        meta: { title: '创建/编辑(集群)角色', icon: 'tree' }
      },
      {
        path: 'salist',
        name: 'Salist',
        component: () => import('@/views/rbac/salist'),
        meta: { title: '服务账号列表', icon: 'tree' }
      },
      {
        path: 'ualist',
        name: 'Ualist',
        component: () => import('@/views/rbac/ualist'),
        meta: { title: '用户账号列表', icon: 'tree' }
      },
      {
        path: 'configyaml',
        name: 'Configyaml',
        component: () => import('@/views/rbac/config-yaml'),
        meta: { title: '查看config文件', icon: 'tree' },
        hidden: true
      },


    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
